package com.ls.utils;

/**
 * 统一响应结果格式
 * 为了方便调用，使用静态方法
 * sucess
 *     提供几种参数形式
 * error
 */
public class ResResult {
    private Integer code;
    private String msg;
    private Object data;
    //总记录数
    private Long count;

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    //提供静态方法：进一步封装
    //封装成功的返回对象
    public static ResResult success(){
        return new ResResult(0,"操作成功",null);
    }

    //封装成功的返回对象
    public static ResResult success(String message){
        return new ResResult(0,message,null);
    }

    //封装成功的返回对象
    public static ResResult success(Object obj){
        return new ResResult(0,"",obj);
    }

    public static ResResult success(Object obj, Long total){
        return new ResResult(0,"",obj,total);
    }

    //封装成功的返回对象
    public static ResResult success(String msg, Object obj){
        return new ResResult(0,msg,obj);
    }

    //封装错误的返回对象
    public static ResResult error(){
        return new ResResult(500,"操作失败",null);
    }

    //封装错误的返回对象
    public static ResResult error(String message){
        return new ResResult(500,message,null);
    }

    //封装错误的返回对象
    public static ResResult error(String message, Object obj){
        return new ResResult(500,message,obj);
    }

    public ResResult(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }
    public ResResult(String msg){
        this.msg = msg;
    }

    public ResResult(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResResult(Integer code, String msg, Object data, Long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
